﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefProcessRoute" :model="stateProcessRoute.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_RoutingName_FormItem" prop="Entity.RoutingName"
											:label="$t('message.autotrans._Model_ProcessRoute_RoutingName')"
											:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRoute_RoutingName')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessRoute.vmModel.Entity.RoutingName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_RoutingCode_FormItem" prop="Entity.RoutingCode"
											:label="$t('message.autotrans._Model_ProcessRoute_RoutingCode')"
											:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRoute_RoutingCode')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessRoute.vmModel.Entity.RoutingCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_ProductId_FormItem" prop="Entity.ProductId"
											:label="$t('message.autotrans._Model_ProcessRoute_ProductId')"
											:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRoute_ProductId')}), trigger: 'blur' }]" >

					<el-select v-model="stateProcessRoute.vmModel.Entity.ProductId" @change="OnProductChange" clearable>
						<el-option v-for="item in stateProcessRoute.AllProducts" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
					</el-select>

				</el-form-item>

        </el-col>
<!--        <el-col :xs="24" :lg="24" class="mb20">-->
<!--        <el-form-item ref="Entity_ProductCode_FormItem" prop="Entity.ProductCode" :label="$t('message.autotrans._Model_ProcessRoute_ProductCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRoute_ProductCode')}), trigger: 'blur' }]" >-->
<!--            <el-input v-model="stateProcessRoute.vmModel.Entity.ProductCode" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
<!--        <el-col :xs="24" :lg="24" class="mb20">-->
<!--        <el-form-item ref="Entity_ProductName_FormItem" prop="Entity.ProductName" :label="$t('message.autotrans._Model_ProcessRoute_ProductName')">-->
<!--            <el-input v-model="stateProcessRoute.vmModel.Entity.ProductName" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Active_FormItem" prop="Entity.Active" :label="$t('message.autotrans._Model_ProcessRoute_Active')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRoute_Active')}), trigger: 'blur' }]" >
            <el-switch v-model="stateProcessRoute.vmModel.Entity.Active" clearable></el-switch>
        </el-form-item>

        </el-col>
<!--        <el-col :xs="24" :lg="24" class="mb20">-->
<!--        <el-form-item ref="Entity_Aux_1_FormItem" prop="Entity.Aux_1" :label="$t('message.autotrans._Model_ProcessRoute_Aux_1')">-->
<!--            <el-input v-model="stateProcessRoute.vmModel.Entity.Aux_1" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
<!--        <el-col :xs="24" :lg="24" class="mb20">-->
<!--        <el-form-item ref="Entity_Aux_2_FormItem" prop="Entity.Aux_2" :label="$t('message.autotrans._Model_ProcessRoute_Aux_2')">-->
<!--            <el-input v-model="stateProcessRoute.vmModel.Entity.Aux_2" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
      </el-row>

      <WtmTable ref="tableRefProcessRouteItemRoutieList1" v-bind="tableDataProcessRouteItemRoutieList1" v-model="stateProcessRoute.vmModel.Entity.ProcessRouteItem_Routie"></WtmTable>
      <div style="text-align:right;">
        <WtmButton @click="onSubmitProcessRoute"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseProcessRoute"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageProcessManagementProcessRouteEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { processrouteApi } from '/@/api/processmanagement/processroute';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const tableRefProcessRouteItemRoutieList1 = ref();
const tableDataProcessRouteItemRoutieList1 = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
		{title:ci.proxy.$t('message.autotrans.Page工艺位置'),key: 'Pos',type: 'number',isCheck: true,sortable: 'custom',colWidth:180},
		{title:ci.proxy.$t('message.autotrans.Page关联设备'),key: 'EquipmentId',type: 'combobox',isDisabled:true,colWidth:180,comboData:'/api/EquipmentManagement/EquipAlarmRecord/GetEquipments',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工序组'),key: 'GroupCode',type: 'textbox',colWidth:120,isCheck: true,sortable: 'custom'},
      {title:ci.proxy.$t('message.autotrans.Page工序编号'),key: 'OpCode',type: 'textbox',sortable: 'custom',colWidth:150,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工序名称'),key: 'OpName',type: 'textbox',colWidth:150,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工序类型'),key: 'OpType',type: 'combobox',colWidth:180,comboData:{
                Assembling:ci.proxy.$t('message.autotrans._Enum_OpTypeEnum_Assembling'),
                Detection:ci.proxy.$t('message.autotrans._Enum_OpTypeEnum_Detection'),
                Rework:ci.proxy.$t('message.autotrans._Enum_OpTypeEnum_Rework'),
                TakePartInOrOut:ci.proxy.$t('message.autotrans._Enum_OpTypeEnum_TakePartInOrOut'),
                Weild:ci.proxy.$t('message.autotrans._Enum_OpTypeEnum_Weild'),
                PrintMark:ci.proxy.$t('message.autotrans._Enum_OpTypeEnum_PrintMark'),
                Fds:ci.proxy.$t('message.autotrans._Enum_OpTypeEnum_Fds'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工厂工序'),key: 'ErpOpCode',type: 'textbox',colWidth:150,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page标准加工工时'),key: 'StdOpDuration',type: 'number',colWidth:180,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page标准准备工时'),key: 'StdPrepDuration',type: 'number',colWidth:180,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page校验上一工序动作'),key: 'PolicyCheckPrevProc',type: 'combobox',comboData:{
                None:ci.proxy.$t('message.autotrans._Enum_PolicyCheckPrevProcEnum_None'),
                Worked:ci.proxy.$t('message.autotrans._Enum_PolicyCheckPrevProcEnum_Worked'),
                WorkedAndOK:ci.proxy.$t('message.autotrans._Enum_PolicyCheckPrevProcEnum_WorkedAndOK'),},isCheck: true,colWidth:180,},
      {title:ci.proxy.$t('message.autotrans.Page校验生产BOM动作'),key: 'PolicyCheckProcBom',type: 'combobox',colWidth:180,comboData:{
                None:ci.proxy.$t('message.autotrans._Enum_PolicyCheckProcBomEnum_None'),
                Over:ci.proxy.$t('message.autotrans._Enum_PolicyCheckProcBomEnum_Over'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工艺校验策略'),key: 'PolicyCheckProcess',type: 'combobox',colWidth:180,comboData:{
					      None:ci.proxy.$t('message.autotrans._Enum_PolicyCheckProcBomEnum_None'),
                AllowedEntryRepeat:ci.proxy.$t('message.autotrans._Enum_PolicyCheckProcessEnum_AllowedEntryRepeat'),
                CheckBOMSource:ci.proxy.$t('message.autotrans._Enum_PolicyCheckProcessEnum_CheckBOMSource'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page工艺管控属性'),key: 'CtlAttr',type: 'combobox',colWidth:180,comboData:{
                Must:ci.proxy.$t('message.autotrans._Enum_ProcCtlAttrEnum_Must'),
                Optional:ci.proxy.$t('message.autotrans._Enum_ProcCtlAttrEnum_Optional'),},isCheck: true},

      {title:ci.proxy.$t('message.autotrans.Page处理标记'),key: 'Etag',type: 'textbox',colWidth:180,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page激活'),key: 'Active',type: 'switch',defaultValue:true,comboData:
                {true:ci.proxy.$t('message._system.common.vm.tips_bool_true'),
                  false:ci.proxy.$t('message._system.common.vm.tips_bool_false')},isCheck: true},

      // {title:ci.proxy.$t('message.autotrans.Page设备编号'),key: 'EquipmentCode',type: 'textbox',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: false, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
        isSub:true,
        isDisabled:false
	}
});

// 定义变量内容
const formRefProcessRoute = ref();
const stateProcessRoute = reactive({
    vmModel: {
	  Entity:{
        RoutingName: '',
        RoutingCode: '',
        ProductId: null,
        LindId:null,
        ProductCode: '',
        ProductName: '',
        Active: undefined,
        Aux_1: '',
        Aux_2: '',
        ProcessRouteItem_Routie:[],
        ID:null,
      },

	},
	  AllProducts:[] as any[],
    AllRouties: [] as any[],
    AllProductLines:[] as any[],
});

// 取消
const onCloseProcessRoute = () => {
    closeDialog();
};

// 提交
const onSubmitProcessRoute = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefProcessRoute.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            processrouteApi().edit(stateProcessRoute.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

//产品选择时
const OnProductChange= (value: any)  =>
{
	if (value)
  {
  
		const prod = stateProcessRoute.AllProducts.find(item => item.Value === value);
		stateProcessRoute.vmModel.Entity.ProductCode = prod.Text;
     if(stateProcessRoute.AllProductLines)
		 {
            stateProcessRoute.vmModel.Entity.LindId=stateProcessRoute.AllProductLines[0].value;
		 }
	}
	else{
		stateProcessRoute.vmModel.Entity.ProductCode='';
	}


}


// 页面加载时
onMounted(() => {
	other.getSelectList('/api/ProductManagement/ProductBom/GetProducts',[],false).then(x=>{stateProcessRoute.AllProducts = x});
    other.getSelectList('/api/ProcessManagement/ProcessRouteItem/GetProcessRoutes',[],false).then(x=>{stateProcessRoute.AllRouties = x});
    if (ci.attrs["wtmdata"]) {
		stateProcessRoute.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateProcessRoute.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	processrouteApi().get(stateProcessRoute.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateProcessRoute.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

